package com.bdzl.biz.controller;

import java.util.List;
import java.util.Map;
import java.util.Queue;

import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.vo.loan.BizAreaVO;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.bdzl.pub.entity.loan.BizAreaDO;
import com.bdzl.biz.service.BizAreaService;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;

/**
 * 业务区域信息表
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-11 15:23:42
 */

@Controller
@RequestMapping("/bdzl/bizArea")
public class BizAreaController extends BaseController {
    @Autowired
    private BizAreaService bizAreaService;

    @GetMapping()
    String BizArea() {
        return "bdzl/bizArea/bizArea";
    }

    @ResponseBody
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<BizAreaDO> bizAreaList = bizAreaService.list(query);
        int total = bizAreaService.count(query);
        PageUtils pageUtils = new PageUtils(bizAreaList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    String add() {
        return "bdzl/bizArea/add";
    }

    @GetMapping("/edit/{baId}")
    @ResponseBody
    R edit(@PathVariable("baId") Integer baId) {
        BizAreaVO bizArea = bizAreaService.getAll(baId);
       return R.ok(bizArea);
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    public R save(@RequestBody BizAreaDO bizArea) {
		bizArea.setBaCreator(super.getUserId());
        if (bizAreaService.save(bizArea) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    public R update(@RequestBody BizAreaDO bizArea) {
        bizAreaService.update(bizArea);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/remove/{baId}")
    @ResponseBody
    public R remove(@PathVariable("baId") Integer baId) {
        if (bizAreaService.remove(baId) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    public R remove(@RequestParam("ids[]") Integer[] baIds) {
        bizAreaService.batchRemove(baIds);
        return R.ok();
    }


    @ResponseBody
    @GetMapping("/listAll")
    public PageUtils listAll(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<BizAreaVO> bizAreaList = bizAreaService.listAll(query);
        query.put("offset", null);
        query.put("limit", null);
        List<BizAreaVO> bizAreaListtoel = bizAreaService.listAll(query);
        int total = 0;
        if (bizAreaListtoel != null) {
            total = bizAreaListtoel.size();
        }
        PageUtils pageUtils = new PageUtils(bizAreaList, total);
        return pageUtils;
    }

    /**
     * 查询user
     * @param params
     * @return
     */
    @ResponseBody
    @GetMapping("/userList")
    public PageUtils userList(@RequestParam Map<String, Object> params){
        Query query = new Query(params);
        return  bizAreaService.userList(query);
    }

}
